package it.polimi.travelDreamEJB.travelpacketmanagement;

import it.polimi.travelDreamEJB.basicproductmanagement.Excursion;
import it.polimi.travelDreamEJB.basicproductmanagement.Flight;
import it.polimi.travelDreamEJB.basicproductmanagement.Hotel;
import it.polimi.travelDreamEJB.personalizedpacketmanagement.dto.PersonalizedPacketDTO;
import it.polimi.travelDreamEJB.usermanagement.User;

import java.io.Serializable;

import javax.persistence.*;

import java.util.ArrayList;
import java.util.List;

/**
 * The persistent class for the personalized_packet database table.
 * 
 */
@Entity
@Table(name = "personalized_packet")
@NamedQueries({
@NamedQuery(name = "PersonalizedPacket.findAll", query = "SELECT p FROM PersonalizedPacket p"),
@NamedQuery(name = "PersonalizedPacket.findPersonalizedPacket", query = "SELECT p FROM PersonalizedPacket p JOIN p.user u WHERE u.email LIKE :email"),
@NamedQuery(name = "PersonalizedPacket.findGuestPacket", query = "SELECT p FROM PersonalizedPacket p JOIN p.guest u WHERE u.email LIKE :email"),
@NamedQuery(name = "PersonalizedPacket.findBoughtPacket", query = "SELECT p FROM PersonalizedPacket p JOIN p.buyer u WHERE u.email LIKE :email"),
})
public class PersonalizedPacket implements Serializable {
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "id_personalized_packet")
	private int idPersonalizedPacket;

	// @Column(name = "id_hotel") private int idHotel;
	// bi-directional many-to-one association to Hotel
	@ManyToOne
	@JoinColumn(name = "id_hotel")
	private Hotel hotel;

	@ManyToOne
	@JoinColumn(name = "id_departure_flight")
	private Flight departureFlight;

	@ManyToOne
	@JoinColumn(name = "id_return_flight")
	private Flight returnFlight;

	// bi-directional many-to-one association to User
	@ManyToOne
	@JoinColumn(name = "email")
	private User user;

	// bi-directional many-to-many association to Excursion
	@ManyToMany
	@JoinTable(name = "personalized_packet_excursions", joinColumns = { @JoinColumn(name = "id_personalized_packet", referencedColumnName = "id_personalized_packet") }, inverseJoinColumns = { @JoinColumn(name = "id_excursion", referencedColumnName = "id_excursion") })
	private List<Excursion> excursions;

	// bi-directional many-to-many association to User
	@ManyToMany
	@JoinTable(name = "boughted_personalized_packet", joinColumns = { @JoinColumn(name = "id_personalized_packet", referencedColumnName = "id_personalized_packet") }, inverseJoinColumns = { @JoinColumn(name = "email", referencedColumnName = "EMAIL") })
	private List<User> buyer;

	// bi-directional many-to-many association to User
	@ManyToMany
	@JoinTable(name = "invited_personalized_packet", joinColumns = { @JoinColumn(name = "id_personalized_packet", referencedColumnName = "id_personalized_packet") }, inverseJoinColumns = { @JoinColumn(name = "email", referencedColumnName = "EMAIL") })
	private List<User> guest;

	public PersonalizedPacket() {
	}

	public PersonalizedPacket(PersonalizedPacketDTO personalizedPacket) {

		this.guest = new ArrayList<User>();
		this.buyer = new ArrayList<User>();
		this.excursions = new ArrayList<Excursion>();

		// this.idPersonalizedPacket = personalizedPacket.getId_personalized_packet();
		// this.user = new User(personalizedPacket.getUser());
		// this.idHotel = personalizedPacket.getId_hotel();
		// this.departureFlight = personalizedPacket.getDepartureFlight();
		// this.idReturnFlight = personalizedPacket.getId_return_flight();

	}

	public int getIdPersonalizedPacket() {
		return this.idPersonalizedPacket;
	}

	public void setIdPersonalizedPacket(int idPersonalizedPacket) {
		this.idPersonalizedPacket = idPersonalizedPacket;
	}

	public User getUser() {
		return this.user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public List<Excursion> getExcursions() {
		return this.excursions;
	}

	public void setExcursions(List<Excursion> excursions) {
		this.excursions = excursions;
	}

	public List<User> getBuyer() {
		return buyer;
	}

	public List<User> getGuest() {
		return guest;
	}

	public void setBuyer(List<User> buyer) {
		this.buyer = buyer;
	}

	public void setGuest(List<User> guest) {
		this.guest = guest;
	}

	public Hotel getHotel() {
		return hotel;
	}

	public void setHotel(Hotel hotel) {
		this.hotel = hotel;
	}

	public Flight getDepartureFlight() {
		return departureFlight;
	}

	public Flight getReturnFlight() {
		return returnFlight;
	}

	public void setDepartureFlight(Flight departureFlight) {
		this.departureFlight = departureFlight;
	}

	public void setReturnFlight(Flight returnFlight) {
		this.returnFlight = returnFlight;
	}

}